﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class Web_Login : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        Session["current"] = "";//CURRENT PAGE
        if (Request.QueryString["ER"] != null)//USER NAME OR PASSWORD ERROR
            log.Text = Request.QueryString["ER"];
    }

    protected void ASPxButton1_Click(object sender, EventArgs e)
    {

        Bestlife.ERP.Entities.Login user = new Bestlife.ERP.Entities.Login();
        user.User_Name1 = ASPxTextBox1.Text;
        user.Password1 = ASPxTextBox2.Text;
        Session["username"] = ASPxTextBox1.Text;

        string usertype = Bestlife.ERP.BusinessRules.userlogin.user(user);
        Session["user"] = usertype;
        if (usertype == "admin")
        {

            Response.Redirect("LogSuccess.aspx");
        }
        else
            if (usertype == "storekeeper")
            {
                Response.Redirect("Store_Keeper/logsucess.aspx");
            }
            else

                if (usertype == "cashier")
                {
                    Response.Redirect("Cashier/LogsuxCash.aspx");
                }
                else

                    if (usertype == "topviewer")
                    {
                        Response.Redirect("Top Manager/logsucess.aspx");
                    }
                    else

                    if (usertype == "superuser")
                    {
                        Response.Redirect("Store Manager/SM_logsuccess.aspx");
                    }
                    else
                        if (usertype == "kandy")
                        {
                            Response.Redirect("Kandy/K_logsux.aspx");

                        }
                        else
                            if (usertype == "viewer")
                            {
                                Response.Redirect("viewer/logsucess.aspx");
                            }
                        else
                        {
                            Response.Redirect("index.aspx?ER=Your user ID or Password is incorrect");
                        }



    }
}

    